﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LenderClearingHouse
{
  public partial class SaveViewAsDialog : PageBase
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
        tbNameSettings.Text = Session["NameSettingsCurrent"].ToString();
        if (tbNameSettings.Text == "(Empty)")
          tbNameSettings.Text = "";
        chkFlagGlobal.Checked = Convert.ToBoolean(Session["CurrentViewFlagGlobal"]);
      }
    }

    protected void btnSave_Click(Object sender, EventArgs e)
    {
      DataAccess da = new DataAccess();
      DataTable dt = da.GetDataTable("testGridSettings", new string[] { "@NameSettingsOld", "@NameSettingsNew", "@SettingsUserId", "@CurrentUserId" },
         new object[] { Session["NameSettingsCurrent"], tbNameSettings.Text, Session["CurrentViewUserId"].ToString(), CurrentUser.UserId });

      if (Convert.ToInt32(dt.Rows[0]["IdErr"]) == 0)
      {
        Session["NameSettingsNew"] = tbNameSettings.Text;
        Session["FlagGlobalNew"] = chkFlagGlobal.Checked;

        ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "CloseAndRefresh();", true);
      }
      else
        ScriptManager.RegisterStartupScript(this, this.GetType(), "key", string.Format("alert('{0}');", dt.Rows[0]["MsgErr"].ToString()), true);
    }
  }
}